

package com.hazelcast.sql;

import com.hazelcast.spi.annotation.PrivateApi;

import javax.annotation.Nonnull;

/**
 * SQL column metadata.
 */
public final class SqlColumnMetadata {

    private final String name;
    private final SqlColumnType type;
    private final boolean nullable;

    @PrivateApi
    @SuppressWarnings("ConstantConditions")
    public SqlColumnMetadata(@Nonnull String name, @Nonnull SqlColumnType type, boolean nullable) {
        assert name != null;
        assert type != null;

        this.name = name;
        this.type = type;
        this.nullable = nullable;
    }

    /**
     * Get column name.
     *
     * @return column name
     */
    @Nonnull
    public String getName() {
        return name;
    }

    /**
     * Gets column type.
     *
     * @return column type
     */
    @Nonnull
    public SqlColumnType getType() {
        return type;
    }

    /**
     * Gets column nullability.
     *
     * @return column type
     */
    public boolean isNullable() {
        return nullable;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        SqlColumnMetadata that = (SqlColumnMetadata) o;

        if (!name.equals(that.name)) {
            return false;
        }

        return nullable == that.nullable && type == that.type;
    }

    @Override
    public int hashCode() {
        int result = name.hashCode();

        result = 31 * result + type.hashCode();
        result = 31 * result + Boolean.hashCode(nullable);

        return result;
    }

    @Override
    public String toString() {
        return name + ' ' + type;
    }
}
